package com.scanbarcode;

import java.util.HashMap;

import com.commonfunction.CommFunction;
import com.databasefunction.AllDBFunction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ViewBarcodeData extends ActionSupport{
	
	private String barcode;
	private String userrole;
	private HashMap barcodeData;
	
	public String getBarcode() {
		return barcode;
	}

	public void setBarcode(String barcode) {
		this.barcode = barcode;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		AllDBFunction allDBFunction = new AllDBFunction();
		if(null==barcode){
			barcode = (String) ActionContext.getContext().getSession().get("barcodeadmin");
		}else{
			ActionContext.getContext().getSession().put("barcodeadmin", barcode);
		}
		
		if(null!=barcode){
			barcodeData = allDBFunction.getBarcodeInfo(barcode);
		 	ActionContext.getContext().getSession().put("barcodeadmindata", barcodeData);
		}else{
			return "unauthorised";
		}
		
		if ((null != userrole) && (userrole.equals("admin") || userrole.equals("superadmin"))) {
		
		}else
			return "unauthorised";
		
		
		System.out.println("In BarcodeCheck funtion.....");
		return "success";
	}
	
	@Override
	public void validate() {
		// TODO Auto-generated method stub
		userrole = (String) ActionContext.getContext().getSession().get("userrole");
		CommFunction commFunction = new CommFunction();
		if (!commFunction.isBarcodePresent(barcode)) {
			addActionError("Barcode not found Please scan again");
		}
	}
}
